package com.cos.shop.entity;

/**
 * @author: COS
 * @time: 2022/2/24 9:19
 * @description:
 */
public class PageHelper {
    //当前页码
    private int pageIndex;
    //每页显示行数
    private int pages;
    //总页数
    private int totalPages;
    //数据总条数
    private int totalCount;
    //起始行数
    private int startRow;

    public PageHelper(int pageIndex, int pages, int totalCount) {
        this.totalCount = totalCount;
        this.pages = pages;
        this.totalPages = (int) Math.ceil(this.totalCount / (this.pages + 0.0));
        if (pageIndex < 0) {
            this.pageIndex = 1;
        } else if (pageIndex >= this.totalPages) {
            this.pageIndex = this.totalPages;
        } else {
            this.pageIndex = pageIndex;
        }
        this.startRow = (this.pageIndex - 1) * this.pages;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getStartRow() {
        return startRow;
    }

    public void setStartRow(int startRow) {
        this.startRow = startRow;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }
}
